package brosim.jobs;
import brosim.bean.Equipment;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author Hugo
 */
public class Personagem implements IPersonagem {
    protected String jobName;
    protected int[][] bonusJob;
    protected int jobID;
    protected int extendsJob;
    
    protected String name;
    protected int hairID;
    protected int hairColor;
    protected int sex;
    
    protected int STR = 1;
    protected int AGI = 1;
    protected int VIT = 1;
    protected int INT = 1;
    protected int DEX = 1;
    protected int LUK = 1;
    protected int bSTR = 1;
    protected int bAGI = 1;
    protected int bVIT = 1;
    protected int bINT = 1;
    protected int bDEX = 1;
    protected int bLUK = 1;
    protected int tSTR = 1;
    protected int tAGI = 1;
    protected int tVIT = 1;
    protected int tINT = 1;
    protected int tDEX = 1;
    protected int tLUK = 1;
    
    protected Equipment eqTopHead = new Equipment();
    protected Equipment eqMidHead = new Equipment();
    protected Equipment eqLowHead = new Equipment();
    protected Equipment eqLeftHand = new Equipment();
    protected Equipment eqRightHand = new Equipment();
    protected Equipment eqGarment = new Equipment();
    protected Equipment eqArmour = new Equipment();
    protected Equipment eqShoes = new Equipment();
    protected Equipment eqLeftAccessory = new Equipment();
    protected Equipment eqRightAccessory = new Equipment();
    protected Equipment eqAmmunition = new Equipment();
    
    protected boolean baby = false;
    protected boolean trans;
    protected int stPoint = 0;
    protected int baseLV = 1;
    protected int jobLV = 1;
    protected int baseHP = 0;
    protected int maxHP = 0;
    protected int baseSP = 0;
    protected int maxSP = 0;
    protected int cast = 100;
    private int DEF;
    private int[] vitDEF = new int[3];
    private int MDEF;
    
    // Fatores
    protected double hpMultiplier;
    protected double hpFactor;
    protected double spFactor;
    protected double weightFactor;
    
    
    public Personagem(String name, int hairID, int hairColor, int sex, int STR, int AGI, int VIT, int INT, int DEX, int LUK) {
        setName(name);
        setHairID(hairID);
        setHairColor(hairColor);
        setSex(sex);
        setStr(STR);
        setAgi(AGI);
        setVit(VIT);
        setInt(INT);
        setDex(DEX);
        setLuk(LUK);
    }
    
    public void allCalc() {
        stCalc();
        stPlusCalc();
        hpCalc();
        spCalc();
        castCalc();
    }
    
    public void stCalc() {
        int stPointU = 0;
        int stPointG = 48;
        if (trans) stPointG = 100;
        int i = 0;
        for (i = 2;i <= STR;i++)
            stPointU += stCalcNeedPoint(i);
        for (i = 2;i <= AGI;i++)
            stPointU += stCalcNeedPoint(i);
        for (i = 2;i <= VIT;i++)
            stPointU += stCalcNeedPoint(i);
        for (i = 2;i <= INT;i++)
            stPointU += stCalcNeedPoint(i);
        for (i = 2;i <= DEX;i++)
            stPointU += stCalcNeedPoint(i);
        for (i = 2;i <= LUK;i++)
            stPointU += stCalcNeedPoint(i);
        
        for (i=1;stPointU > stPointG && i<99;i++)
            stPointG += java.lang.Math.floor(i/5) + 3;
        
        if (i > 99)
            i=99;
        
        baseLV = i;
        stPoint = stPointG - stPointU;
    }
    
    public int stCalcNeedPoint(int i) {
        return (int)java.lang.Math.floor((i - 2) /10) + 2;
    }
    
    public void stPlusCalc() {
        bSTR = bonusJob[jobLV-1][0];
        bAGI = bonusJob[jobLV-1][1];
        bVIT = bonusJob[jobLV-1][2];
        bINT = bonusJob[jobLV-1][3];
        bDEX = bonusJob[jobLV-1][4];
        bLUK = bonusJob[jobLV-1][5];
        
        int equipStatsBonus = new Double(bonusAllEquip(42)).intValue();
        bSTR += bonusAllEquip(11) + equipStatsBonus;
        bAGI += bonusAllEquip(12) + equipStatsBonus;
        bVIT += bonusAllEquip(13) + equipStatsBonus;
        bINT += bonusAllEquip(14) + equipStatsBonus;
        bDEX += bonusAllEquip(15) + equipStatsBonus;
        bLUK += bonusAllEquip(16) + equipStatsBonus;
        
        bDEX += searchSkill(38); 			//@skill Owl's Eye (Archer)
        bSTR += searchActiveSkill(68) * 4; 	//@skill Crazy Uproar (Merchant)
        bSTR += searchSkill(146); 			//@skill Hilt Binding (BlackSmith)
        bSTR += searchActiveSkill(404); 	//@skill Ninja Aura
        bINT += searchActiveSkill(404); 	//@skill Ninja Aura
        
        //@skill Dragonology (Sage)
        if (searchSkill(234) > 0)
            bINT += (Math.floor(searchSkill(234) /2) +1);
        
        //@skill Chase Walk (Stalker)
        if (searchActiveSkill(286) > 0){
        	bSTR += 2^(searchActiveSkill(286)-1);
        }
        
        //@skill Increase Accuracy (Guslinger)
        if (searchSkill(422) > 0){
            bDEX += 4;
            bAGI += 4;
        }
        
        //@skill Improve Concentration (Archer)
        int skillLV = searchActiveSkill(42);
        
        if (skillLV > 0) {
            skillLV += 102;
            bDEX = (int)Math.floor((DEX + bDEX) * skillLV / 100) - DEX;
            bAGI = (int)Math.floor((AGI + bAGI) * skillLV / 100) - AGI;
        }
        
        int cardStatsBonus = new Double(bonusAllCard(7)).intValue();
        bSTR += bonusAllCard(1) + cardStatsBonus;
        bAGI += bonusAllCard(2) + cardStatsBonus;
        bVIT += bonusAllCard(3) + cardStatsBonus;
        bINT += bonusAllCard(4) + cardStatsBonus;
        bDEX += bonusAllCard(5) + cardStatsBonus;
        bLUK += bonusAllCard(6) + cardStatsBonus;
        
        //@card Rideword
        if (getJobID() == 3)
            bINT += searchCard(18);
        
        //@card Zealtus + Injustice
        if (searchCard(215) > 0 && searchCard(178) > 0)
            bLUK += 3;
        
        //@card Incubus + Succubus
        if (searchCard(32) > 0 && searchCard(68) > 0){
            bINT += 4;
            bVIT += 4;
        }
        
        //@card Cramp + Tarou
        if (searchCard(24) > 0 && searchCard(290) > 0)
            bSTR += 3;
        
        //@card Grand Peco + Peco Peco
        if (searchCard(15) > 0 && searchCard(45) > 0)
            bVIT += 3;
        
        //@card Yao Jun + Munak + Bongun
        if (searchCard(249) > 0 && searchCard(202) > 0 && searchCard(318) > 0){
            bSTR += 1;
            bAGI += 1;
            bVIT += 1;
            bINT += 1;
            bDEX += 1;
            bLUK += 1;
        }
        
        //@setcard Assaulter + Permeter + Solider + Heater + Freezer
        if (searchSetCard(1))
            bSTR += 10;
        
        //@setcard The Paper + Wanderer + Wild Rose + Zhu Po Long + Shinobi
        if (searchSetCard(2)){
            bSTR += 5;
            bAGI += 5;
        }
        
        //@setcard Seal + Rideword + Enchanted Peach Tree + Geographer + Cookie(Green)
        if (searchSetCard(3))
            bVIT += 10;
        
        //@setcard Cruiser + Anoliant + Dragon Tail + Merman + Alligator
        if (searchSetCard(4)){
            bDEX += 3;
            bAGI += 5;
        }
        
        //@setcard Zipper Bear + Myst Case + Baby Leopard + Raggler + Heirozoist
        if (searchSetCard(6))
            bLUK += 10;
        
        //@skill Bless (Priest)
        bSTR += searchActiveSkill(9);
        bINT += searchActiveSkill(9);
        bDEX += searchActiveSkill(9);
        
        //@skill Agi (Priest)
        if (searchActiveSkill(10) > 0)
            bAGI += searchActiveSkill(10) + 2;
        
        //@skill Glory (Priest)
        bLUK += (searchActiveSkill(11) * 30);
        
        //@skill Falcon Eyes (Sniper)
        if (getJobID() == 24 && searchActiveSkill(270) > 0) {
            bSTR += 5;
            bAGI += 5;
            bVIT += 5;
            bDEX += 5;
            bINT += 5;
            bLUK += 5;
        }
        
        //@skill Sprint - Str Bonus (Taekwon)
        if (searchActiveSkill(379) > 0)
            bSTR += 10;
        
        //@skill Battle Orders (Guild)
        if (searchActiveSkill(400) > 0){
            bSTR += 5;
            bDEX += 5;
            bINT += 5;
        }
        
        bSTR += searchActiveSkill(401);//@skill Great Leadership (Guild)
        bVIT += searchActiveSkill(402);//@skill Wounds of Glory (Guild)
        bAGI += searchActiveSkill(403);//@skill Soul of Could (Guild)
        bDEX += searchActiveSkill(404);//@skill Sharp Hawk Eyes (Guild)
        
        //@skill Battle Chant (Paladin)
        if (searchActiveSkill(400) > 0){
            bSTR += 20;
            bAGI += 20;
            bVIT += 20;
            bDEX += 20;
            bINT += 20;
            bLUK += 20;
        }
        
        //@skill Murderer - PVP Bonus
        if (searchActiveSkill(500) == 1){
            bSTR += 3;
            bAGI += 3;
            bVIT += 3;
            bDEX += 3;
            bINT += 3;
            bLUK += 3;
        }
        
        //@skill Murderer - PVP Bonus
        if (searchActiveSkill(500) == 2){
            bSTR += 5;
            bAGI += 5;
            bVIT += 5;
            bDEX += 5;
            bINT += 5;
            bLUK += 5;
        }
        
        //@skill food
        //@not-implemented
        
        
        //@skill Marionette
        //@not-implemented
        
        tSTR = bSTR + STR;
        tAGI = bAGI + AGI;
        tVIT = bVIT + VIT;
        tINT = bINT + INT;
        tDEX = bDEX + DEX;
        tLUK = bLUK + LUK;
        
    }
    
    public void hpCalc() {
        int bonus = 0;
        
        //@job Soul Linker
        int wHPSL = 0;
        if(getJobID() == 43){
            if(70 <= baseLV && baseLV <= 79)
                wHPSL = (baseLV - 69) *40;
            if(80 <= baseLV && baseLV <= 89)
                wHPSL = (baseLV - 79) *50 -10;
            if(90 <= baseLV)
                wHPSL = (baseLV - 89) *50 -10;
        }
        int i;
        for(i = 2; i <= baseLV; i++){
            bonus += Math.round(hpFactor * i /100);
        }
        
        baseHP = (int)Math.floor((hpMultiplier * baseLV) + 35 + bonus);
        
        //@job Super Aprendiz lvl 99
        if(jobID == 20 && baseLV == 99)
            baseHP += 2000;
        
        // Transclasse 125% do HP
        if(trans)
            baseHP = (int)java.lang.Math.floor(baseHP *125 /100);
        
        // Personagem adotado 70% do HP
        if(baby)
            baseHP = (int)Math.floor(baseHP *70 /100);
        baseHP -= wHPSL;
        maxHP = baseHP;
        
        // Bonus de VIT
        maxHP = (int)Math.floor(maxHP * (100 + tVIT) / 100);
        System.out.println(maxHP);
        //@job Taekwon
        if(getJobID() == 41 && baseLV >= 70){
            if(baseLV <=79)
                maxHP = (int)Math.floor((2127 + 10 * (baseLV-70)) * (100 + tVIT) / 100);
            else if(baseLV <=89)
                maxHP = (int)Math.floor((2200 + 50 * (baseLV-80)) * (100 + tVIT) / 100);
            else if(baseLV <=99)
                maxHP = (int)Math.floor((2700 + 50 * (baseLV-90)) * (100 + tVIT) / 100);
        }
        
        //@job Mestre Taekwon
        if(getJobID() == 42 && baseLV >= 70){
            double[] wKenseiHP = {3455,3524,3593,3663,3834,3806,3821,3836,3851.5,4500};
            if(baseLV <=79)
                maxHP = (int)Math.floor((2670 + 10 * (baseLV-70)) * (100 + tVIT) / 100);
            else if(baseLV <=89)
                maxHP = (int)Math.floor((3000 + 20 * (baseLV-80)) * (100 + tVIT) / 100);
            else if(baseLV <=97)
                maxHP = (int)Math.floor(wKenseiHP[baseLV-90] * (100 + tVIT) / 100);
        }
        
        //@job Guslinger
        if(getJobID() == 45) {
            int[] wSlingerHP = {0,40,47,54,61,69,77,85,94,103,202,212,222,232,243,254,265,277,289,301,316,331,346,364,382,400,420,440,460,490,520,550,580, 610,650,680,710,740,770,800,830,865,890,925,955,990,1025,1050,1080,1110,1145,1180,1215,1275,1335,1395,1455,1515,1575,1635,1695,1760,1820,1885,1950,2015,2080,2145,2210,2275,2340,2410,2480,2550,2620,2690,2760,2830,2900,2970,3040,3115,3190,3265,3340,3415,3490,3565,3640,3715,3790,3870,3950,4030,4110,4190,4270,4350,4430,4510};
            maxHP = (int)Math.floor(wSlingerHP[baseLV] * (100 + tVIT) / 100);
        }
        
        //@skill Taekwon Rank
        if(searchSkill(345) == 0 &&  baseLV >= 90)
            maxHP *= 3;
        
        //@skill Faith (Crusader)
        maxHP += searchSkill(156) * 200;
        
        int bkHP = maxHP;
        bonus = 0;
        
        // Ekip HP Bonus
        bonus += bonusAllEquipCard(7);
        // Ekip VIT Bonus
        bonus += bonusAllEquipCard(13);
        
        //@card Quve + Lude
        if(searchCard(324) > 0 && searchCard(314) > 0)
            bonus += 300;
        
        //@setcard Evil Nymph + Parasite + Loli Ruri + Harpy + Miyabi Doll + Blood Butterfly
        if (searchSetCard(5))
            bonus += 500;
        
        //@equip Valkyrian Shoes
        if(eqShoes.getId() == 101){
            if(extendsJob == 3 || extendsJob == 4 || extendsJob == 5)
                bonus += 5 * baseLV;
        }
        
        maxHP += bonus;
        
        bonus = 0;
        
        bonus += bonusAllEquipCard(9);
        
        //@card Giant Whisper
        if(tVIT >= 80 && searchCard(238) > 0)
            bonus += 3;
        
        //@card Dark Illusion e Dark Lord
        if(searchCard(16) > 0 && searchCard(265) > 0)
            bonus += 20;
        
        //@setcard Assaulter + Permeter + Solider + Heater + Freezer
        if (searchSetCard(1))
            bonus += 20;
        
        //@skill Battle Chant (Paladin)
        if (supportSkill(1)[0] > 0)
            bonus += 100;
        
        maxHP *= (100 + bonus)/100;
        
        //@skill Delug Area (Sage) + (Armour of Ocean or Swordfish Card)
        if (supportSkill(10)[0] >= 1 && (searchCard(51) > 0 || eqArmour.getId() == 67)){
            int[] dHP = {5,9,12,14,15};
            maxHP *= (100 + dHP[supportSkill(10)[0]-1]) /100;
        }
        
        //@skill Frenzy (LK)
        if (searchActiveSkill(258) == 1)
            maxHP *= 3;
        
        //@skill Songs Of Lutie (Bard)
        if (supportSkill(3)[0] > 0)
            maxHP += (Math.floor(bkHP * (105 + supportSkill(3)[0] *2 + supportSkill(3)[1] + Math.floor(supportSkill(3)[2] /10)) /100) - bkHP);
        
        maxHP = (int)Math.floor(maxHP);
        
    }
    
    public void spCalc() {
        int bonus = 0;
        int wSPSL = 0;
        
        //@job Taekwon ou Soul Linker
        if (getJobID() == 41 || getJobID() == 43){
            if(70 <= baseLV && baseLV <= 80)
                wSPSL = (baseLV - 69) *4 +1;
            if(80 <= baseLV && baseLV <= 90)
                wSPSL = (baseLV - 79) *4 -4;
            if(90 <= baseLV)
                wSPSL = (baseLV - 89) *4 -14;
        }
        
        maxSP = (int)Math.floor(10 + baseLV * spFactor - wSPSL);
        
        // Transclasse 125%
        if (trans)
            maxSP = (int)Math.floor(maxSP * 125 /100);
        
        // Personagem adotado 70% do SP
        if (baby)
            maxSP = (int)Math.floor(maxSP *70 /100);
        
        maxSP = (int)Math.floor(maxSP * (100 + tINT) / 100);
        
        //@job Mestre Taekwon
        if (getJobID() == 42 && baseLV >= 70){
            if(baseLV <=79)
                maxSP = (int)Math.floor((340 + 2 * (baseLV-70)) * (100 + tINT) / 100);
            else if(baseLV <= 89)
                maxSP = (int)Math.floor((385 + 2 * (baseLV-80)) * (100 + tINT) / 100);
            else if(baseLV <= 99)
                maxSP = (int)Math.floor((437 + 2 * (baseLV-90)) * (100 + tINT) / 100);
        }
        
        int bkSP = maxSP;
        
        //@job Taekwon Rank
        if (searchSkill(345) == 1 && baseLV >= 90)
            maxSP *= 3;
        
        bonus = 0;
        
        // SP Bonus Equip
        bonus += bonusAllEquipCard(8);
        // INT Bonus Equip
        bonus += bonusAllEquipCard(4);
        
        //@card Quve + Lude
        if(searchCard(324) > 0 && searchCard(314) > 0)
            bonus += 60;
        
        //@skill Kaina
        if (searchSkill(372) > 0)
            bonus += 30 * searchSkill(372);
        
        //@card Carat +9
        if ((eqTopHead.getRefine() >= 9 && eqTopHead.searchCard(23) > 0 ))
            bonus += 150;
        if ((eqMidHead.getRefine() >= 9 && eqTopHead.searchCard(23) > 0 ))
            bonus += 150;
        
        //@equip Valkyrian Shoes
        if(eqShoes.getId() == 536){
            if(extendsJob == 1 || extendsJob==2 || extendsJob==6)
                bonus += 2 * jobLV;
        }
        
        maxSP += bonus;
        bonus=0;
        
        
        bonus += bonusAllEquipCard(10);
        
        //@card Dark Illusion + Dark Lord
        if(searchCard(16) > 0 && searchCard(265) > 0)
            bonus += 20;
        
        //@skill Mediatio (HP)
        bonus += searchSkill(269);
        
        //@skill Soul Drain (HW)
        bonus += searchSkill(274) *2;
        
        //@skill Battle Chant (Paladin)
        if (supportSkill(1)[0] > 0)
            bonus += 100;
        
        maxSP *= Math.floor((100 + bonus)/100);
        
        //@skill Gypsy's Kiss (Dancer)
        if (supportSkill(4)[0] > 0)
            maxHP += (Math.floor(bkSP * (105 + supportSkill(4)[0] *2 + supportSkill(4)[1] + Math.floor(supportSkill(4)[2] /10)) /100) - bkSP);
        
    }
    
    public void castCalc() {
        cast = 100 - tDEX*10 / 15;
        if(cast < 0)
            cast = 0;
        
        int bonus = 100;
        
        //@card Dark Illusion + Dark Lord
        if (searchCard(16) > 0 && searchCard(265) > 0)
            bonus -= 20;
        
        //@setcard Seal + Rideword + Enchanted Peach Tree + Geographer + Cookie(Green)
        if (searchSetCard(3))
            bonus -= 10;
        
        //@setcard Evil Nymph + Parasite + Loli Ruri + Harpy + Miyabi Doll + Blood Butterfly
        if (extendsJob == 5 && searchSetCard(5))
            bonus -= 15;
        
        // Cast Time Bonus
        bonus += bonusAllEquipCard(24);
        
        cast *= bonus /100;
        
        //@skill Suffragium (Priest)
        if (supportSkill(90)[0] > 0)
            cast *= (100 - 15 * supportSkill(90)[0]) /100;
        
        //@skill Foresight(Scholar)
        if (supportSkill(322)[0] > 0)
            cast = cast /2;
        
    }
    
    public void defCalc() {
    	DEF = 0;
    	DEF += eqTopHead.getAllDef();
    	DEF += eqMidHead.getAllDef();
    	DEF += eqLowHead.getAllDef();
    	DEF += eqLeftHand.getAllDef();
    	DEF += eqRightHand.getAllDef();
    	DEF += eqGarment.getAllDef();
    	DEF += eqArmour.getAllDef();
    	DEF += eqShoes.getAllDef();
    	DEF += eqLeftAccessory.getAllDef();
    	DEF += eqRightAccessory.getAllDef();
    	DEF += eqAmmunition.getAllDef();
    	
    	int perDEF = 0;
    	perDEF += eqTopHead.getAllPerDef();
    	perDEF += eqMidHead.getAllPerDef();
    	perDEF += eqLowHead.getAllPerDef();
    	perDEF += eqLeftHand.getAllPerDef();
    	perDEF += eqRightHand.getAllPerDef();
    	perDEF += eqGarment.getAllPerDef();
    	perDEF += eqArmour.getAllPerDef();
    	perDEF += eqShoes.getAllPerDef();
    	perDEF += eqLeftAccessory.getAllPerDef();
    	perDEF += eqRightAccessory.getAllPerDef();
    	perDEF += eqAmmunition.getAllPerDef();

    	//@card Clock Tower Manager + Punk + Alarm + Clock
    	if (searchCard(20) > 0 && searchCard(247) > 0 && searchCard(269) > 0 && searchCard(86) > 0)
    		DEF += 3;
    	
    	//@card Grand Peco + Peco Peco
    	if (searchCard(15) > 0 && searchCard(45) > 0)
    		DEF += 3;
    	
    	//@setcard Evil Nymph + Parasite + Loli Ruri + Harpy + Miyabi Doll + Blood Butterfly
    	if (searchSetCard(5))
    		DEF += 5;
    	
    	//@equip Luna Bow
    	if (eqLeftHand.getId() == 727){
    		if(eqLeftHand.getRefine() <= 5)
    			DEF += 2;
    		else if(eqLeftHand.getRefine() >= 9)
    			DEF += 5;
    		else
    			DEF += 3;
    	}

    	//@skill Battle Theme (Dancer)
    	if (searchActiveSkill(200) > 0)
    		DEF += 2 + 2 * searchActiveSkill(200);

    	//Refine
    	int refine = 0;
    	refine += eqTopHead.getRefine();
    	refine += eqMidHead.getRefine();
    	refine += eqLowHead.getRefine();
    	refine += eqArmour.getRefine();
    	refine += eqGarment.getRefine();    	
    	refine += eqShoes.getRefine();    	
    	refine += eqLeftAccessory.getRefine();
    	refine += eqRightAccessory.getRefine();    	
    	DEF = DEF + Math.round(refine *2/3);
    	
    	//perDEF
    	DEF *= (100+perDEF)/100;    	

    	//@skill Spear Dynamo (LK)
    	if (searchActiveSkill(256) > 0)
    			DEF = (int)Math.floor(DEF * (1 - 0.05 * searchActiveSkill(256)));
    	
    	//@skill Mental Strength (Monk)
    	if (searchActiveSkill(196) > 0)
    		DEF = 90;

    	//@skill Frenzy (LK)
    	if (searchActiveSkill(258) > 0)
    		DEF = 0;
    	
    	//VIT DEF
    	vitDEF[0] = (int)Math.floor(VIT * 0.5) + (int)Math.floor(VIT * 0.3);
    	vitDEF[2] = (int)Math.floor(VIT * 0.5) + (int)Math.floor(VIT * VIT / 150) -1;
    	
    	if (vitDEF[2] > vitDEF[0]){
    		vitDEF[1] = (vitDEF[0] + vitDEF[2]) / 2;
    	} else {
    		vitDEF[1] = vitDEF[0];
    		vitDEF[2] = vitDEF[0];
    	}
    	
    	//@skill Auto-Berserk
    	if (searchActiveSkill(12) > 0) {
    		for(int i = 0; i <= 2; i++)
    			vitDEF[i] = (int)Math.floor(vitDEF[i] * 0.45);
    	} else {
    		//@item Aloe (Provocar lvl 1)
    		if (searchActiveSkill(120) > 0){
        		for (int i = 0; i <= 2; i++)
    				vitDEF[i] = (int)Math.floor(vitDEF[i] * 0.9);
    		}
    	}
    	/*
   		for(int i = 0; i <= 2; i++)
   			vitDEF[i] *= (int)Math.floor((100+perDEF)/100);
    	*/
    	//@skill Spear Dynamo (LK)
        if (searchActiveSkill(256) > 0){
    		for (int i = 0; i <= 2; i++)
    			vitDEF[i] = (int)Math.floor(vitDEF[i] * (1 - 0.05 * searchActiveSkill(256)));
    	}
    	
    	//@skill Angelus (Priest)
    	if (searchActiveSkill(500) > 0){
    		for(int i = 0; i <= 2; i++)
    			vitDEF[i] = (int)Math.floor(vitDEF[i] * (1 + 0.05 * searchActiveSkill(500)));
    	}
    	
    	//@skill Frenzy (LK)
    	if (searchActiveSkill(258) > 0){
    		for(int i = 0; i <= 2; i++)
    			vitDEF[i] = 0;
    	}
    	
    	// MDEF
    	
    	MDEF = (int)Math.floor(bonusAllEquipCard(6));
    	
    	if (getJobID() == 3 && searchCard(18) > 0)
    		MDEF += 1;
    	
    	if (searchCard(339) > 0 && searchCard(352) > 0 && searchCard(229) > 0 && searchCard(280) > 0)
    		MDEF += 3;
    	
    	//@setcard Evil Nymph + Parasite + Loli Ruri + Harpy + Miyabi Doll + Blood Butterfly
    	if (searchSetCard(5))
    		MDEF += 5;
    		
    	//@card Gibbet
    	if (eqTopHead.searchCard(22) > 0 && eqTopHead.getRefine() <= 5) {
    		MDEF += 5;
    	} else if (eqMidHead.searchCard(22) > 0 && eqMidHead.getRefine() <= 5) {
    		MDEF += 5;
    	} else if (eqLowHead.searchCard(22) > 0 && eqLowHead.getRefine() <= 5) {
    		MDEF += 5;
    	}
    	
    	//@skill Spear Dynamo
    	if (searchActiveSkill(256) > 0)
    		MDEF += 1;
    	
    	//@skill Mental Strength
    	if (searchActiveSkill(196) > 0)
    		MDEF = 90;
    	
    	//@skill Frenzy (LK)
    	if (searchActiveSkill(258) > 0)
    		MDEF = 0;    	
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public int getHairID() {
        return hairID;
    }
    
    public void setHairID(int hairID) {
        this.hairID = hairID;
    }
    
    public int getHairColor() {
        return hairColor;
    }
    
    public void setHairColor(int hairColor) {
        this.hairColor = hairColor;
    }
    
    public int getSex() {
        return sex;
    }
    
    public void setSex(int sex) {
        this.sex = sex;
    }
    
    public int getStr() {
        return STR;
    }
    
    public void setStr(int STR) {
        this.STR = STR;
        stCalc();
    }
    
    public int getAgi() {
        return AGI;
    }
    
    public void setAgi(int AGI) {
        this.AGI = AGI;
        stCalc();
    }
    
    public int getVit() {
        return VIT;
    }
    
    public void setVit(int VIT) {
        this.VIT = VIT;
        stCalc();
    }
    
    public int getInt() {
        return INT;
    }
    
    public void setInt(int INT) {
        this.INT = INT;
        stCalc();
    }
    
    public int getDex() {
        return DEX;
    }
    
    public void setDex(int DEX) {
        this.DEX = DEX;
        stCalc();
    }
    
    public int getLuk() {
        return LUK;
    }
    
    public void setLuk(int LUK) {
        this.LUK = LUK;
        stCalc();
    }
    
    public Equipment getEqTopHead() {
        return eqTopHead;
    }
    
    public void setEqTopHead(Equipment eqTopHead) {
        this.eqTopHead = eqTopHead;
    }
    
    public Equipment getEqMidHead() {
        return eqMidHead;
    }
    
    public void setEqMidHead(Equipment eqMidHead) {
        this.eqMidHead = eqMidHead;
    }
    
    public Equipment getEqLowHead() {
        return eqLowHead;
    }
    
    public void setEqLowHead(Equipment eqLowHead) {
        this.eqLowHead = eqLowHead;
    }
    
    public Equipment getEqLeftHand() {
        return eqLeftHand;
    }
    
    public void setEqLeftHand(Equipment eqLeftHand) {
        this.eqLeftHand = eqLeftHand;
    }
    
    public Equipment getEqRightHand() {
        return eqRightHand;
    }
    
    public void setEqRightHand(Equipment eqRightHand) {
        this.eqRightHand = eqRightHand;
    }
    
    public Equipment getEqGarment() {
        return eqGarment;
    }
    
    public void setEqGarment(Equipment eqGarment) {
        this.eqGarment = eqGarment;
    }
    
    public Equipment getEqArmour() {
        return eqArmour;
    }
    
    public void setEqArmour(Equipment eqArmour) {
        this.eqArmour = eqArmour;
    }
    
    public Equipment getEqShoes() {
        return eqShoes;
    }
    
    public void setEqShoes(Equipment eqShoes) {
        this.eqShoes = eqShoes;
    }
    
    public Equipment getEqLeftAccessory() {
        return eqLeftAccessory;
    }
    
    public void setEqLeftAccessory(Equipment eqLeftAccessory) {
        this.eqLeftAccessory = eqLeftAccessory;
    }
    
    public Equipment getEqRightAccessory() {
        return eqRightAccessory;
    }
    
    public void setEqRightAccessory(Equipment eqRightAccessory) {
        this.eqRightAccessory = eqRightAccessory;
    }
    
    public Equipment getEqAmmunition() {
        return eqAmmunition;
    }
    
    public void setEqAmmunition(Equipment eqAmmunition) {
        this.eqAmmunition = eqAmmunition;
    }
    
    public String getJobName() {
        return jobName;
    }
    
    public int getJobID() {
        return jobID;
    }
    
    public int getBaseLV() {
        return baseLV;
    }
    
    public int getBaseHP() {
        return baseHP;
    }
    
    public int getMaxHP() {
        return maxHP;
    }
    
    public int getStPoint() {
        return stPoint;
    }
    
    public double bonusAllEquip(int id) {
        double value = 0;
        value += eqTopHead.getBonusEquip(id);
        value += eqMidHead.getBonusEquip(id);
        value += eqLowHead.getBonusEquip(id);
        value += eqLeftHand.getBonusEquip(id);
        value += eqRightHand.getBonusEquip(id);
        value += eqGarment.getBonusEquip(id);
        value += eqArmour.getBonusEquip(id);
        value += eqShoes.getBonusEquip(id);
        value += eqLeftAccessory.getBonusEquip(id);
        value += eqRightAccessory.getBonusEquip(id);
        value += eqAmmunition.getBonusEquip(id);
        return value;
    }
    
    public double bonusAllCard(int id) {
        double value = 0;
        value += eqTopHead.getBonusCard(id);
        value += eqMidHead.getBonusCard(id);
        value += eqLowHead.getBonusCard(id);
        value += eqLeftHand.getBonusCard(id);
        value += eqRightHand.getBonusCard(id);
        value += eqGarment.getBonusCard(id);
        value += eqArmour.getBonusCard(id);
        value += eqShoes.getBonusCard(id);
        value += eqLeftAccessory.getBonusCard(id);
        value += eqRightAccessory.getBonusCard(id);
        value += eqAmmunition.getBonusCard(id);
        return value;
    }
    
    public double bonusAllEquipCard(int id) {
        double value = 0;
        value += eqTopHead.getBonusAll(id);
        value += eqMidHead.getBonusAll(id);
        value += eqLowHead.getBonusAll(id);
        value += eqLeftHand.getBonusAll(id);
        value += eqRightHand.getBonusAll(id);
        value += eqGarment.getBonusAll(id);
        value += eqArmour.getBonusAll(id);
        value += eqShoes.getBonusAll(id);
        value += eqLeftAccessory.getBonusAll(id);
        value += eqRightAccessory.getBonusAll(id);
        value += eqAmmunition.getBonusAll(id);
        return value;
    }
    
    public int searchCard(int id) {
        int card = 0;
        card += eqTopHead.searchCard(id);
        card += eqMidHead.searchCard(id);
        card += eqLowHead.searchCard(id);
        card += eqLeftHand.searchCard(id);
        card += eqRightHand.searchCard(id);
        card += eqGarment.searchCard(id);
        card += eqArmour.searchCard(id);
        card += eqShoes.searchCard(id);
        card += eqLeftAccessory.searchCard(id);
        card += eqRightAccessory.searchCard(id);
        card += eqAmmunition.searchCard(id);
        return card;
    }
    
    public boolean searchSetCard(int set) {
        
        // Assaulter + Permeter + Solider + Heater + Freezer
        if (set == 1){
            if (searchCard(156) > 0 && searchCard(25) > 0 &&
                    searchCard(80) > 0 && searchCard(327) > 0 &&
                    searchCard(281) > 0)
                return true;
            return false;
        }
        
        // The Paper + Wanderer + Wild Rose + Zhu Po Long + Shinobi
        if (set == 2){
            if (searchCard(149) > 0 && searchCard(241) > 0 &&
                    searchCard(270) > 0 && searchCard(339) > 0 &&
                    searchCard(334) > 0)
                return true;
            return false;
        }
        
        // Seal + Rideword + Enchanted Peach Tree + Geographer + Cookie(Green)
        if (set == 3){
            if (searchCard(188) > 0 && searchCard(18) > 0 &&
                    searchCard(210) > 0 && searchCard(72) > 0 &&
                    searchCard(340) > 0)
                return true;
            return false;
        }
        
        // Cruiser + Anoliant + Dragon Tail + Merman + Alligator
        if (set == 4){
            if (searchCard(279) > 0 && searchCard(224) > 0 &&
                    searchCard(340) > 0 && searchCard(351) > 0 &&
                    searchCard(230) > 0)
                return true;
            return false;
        }
        
        // Evil Nymph + Parasite + Loli Ruri + Harpy + Miyabi Doll + Blood Butterfly
        if (set == 5){
            if (searchCard(30) > 0 && searchCard(216) > 0 &&
                    searchCard(63) > 0 && searchCard(248) > 0 &&
                    searchCard(267) > 0 && searchCard(326) > 0)
                return true;
            return false;
        }
        
        // Zipper Bear + Myst Case + Baby Leopard + Raggler + Heirozoist
        if (set == 6){
            if (searchCard(181) > 0 && searchCard(19) > 0 &&
                    searchCard(69) > 0 && searchCard(277) > 0 &&
                    searchCard(325) > 0)
                return true;
            return false;
        }
        return false;
    }
    
    public int searchSkill(int id) {
        return 0;
    }
    
    public int searchActiveSkill(int id) {
        return 0;
    }
    
    public int[] supportSkill(int id) {
        int[] skill = {0};
        return skill;
    }
}
